﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WR.BL.BE;
using System.Collections.Generic;
using WR.BL.BCC;

namespace WR.UI.MobWebApp
{
    public partial class cliente : System.Web.UI.Page
    {
        private UserBE _objUsr;

        private void checkLogin()
        {
            lblErrorMsg.InnerHtml = string.Empty;
            _objUsr = (UserBE)Session["UserBE"];
            if (_objUsr == null)
            {
                Response.Redirect("login.aspx");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.checkLogin();

            if (!Page.IsPostBack)
            {
                List<ClientBE> lstClientes = (List<ClientBE>)Session["lstClientes"];
                if (lstClientes != null)
                {
                    lvClientes.DataSource = lstClientes;
                    lvClientes.DataBind();
                }
            }
        }

        protected void btnFind_Click(object o, EventArgs e)
        {
            string strKunnr = txtKunnr.Value.Trim().ToUpper();
            string strName1 = txtName1.Value.Trim();

            lblOkMsg.InnerHtml = string.Empty;
            List<ClientBE> lstClientes = ClientBC.getInstance(Session.SessionID).find(strKunnr, strName1);
            lvClientes.DataSource = lstClientes;
            lvClientes.DataBind();
            Session["lstClientes"] = lstClientes;

            //-- obtener máximo de registros
            string maxcount = string.Empty, strmax = string.Empty; int imax = 0;
            try
            {
                maxcount = HelperBC.getParamValue("MAXCLI");
                strmax = HelperBC.getParamValue("MSGMAXCLI");

                imax = Convert.ToInt16(maxcount);
            }
            catch { imax = 20; }
            if (lstClientes.Count >= imax)
            {
                lblOkMsg.InnerHtml = strmax;
            }
        }
    }
}
